#ifndef CACHE_SERVER_HPP
#define CACHE_SERVER_HPP
#include <cstring>
#include <cctype>
#include <fcntl.h>
#include "wrap.hpp"
#include "json.hpp"
#include "LRU.hpp"
#include <signal.h>
#include "thrd_pool.hpp"
#include "consistenthash.hpp"

#define HEART_BEAT 2
#define KEY_VALUE_REQUEST 0
#define KEY_VALUE_RESPOND 1
#define SHUTDOWN_CACHE 6
#define ADD_CACHE 7
#define REFLESH_IP 10
#define MASTER_IP "127.0.0.1"
#define MASTER_PORT 7000
#define CACHESERV_IP "127.0.0.1"
#define CACHESERV_PORT 8001

using json = nlohmann::json;
struct heartbeat_struct{
    LRUCache *LC;
    ThreadPool *ThrPl;
    ConsistentHash *key_addr;
    std::vector<std::string> *ipport_list;
};
struct pack_taskconnect{
    int sockfd;
    int efd;
    char* buf;
    LRUCache *LC;
};
struct pack_tasklisten{
    struct sockaddr_in *cliaddr;
    int listenfd;
    int num;
    int efd;
};
struct iplistchange_struct{
    int cfd;
    bool exit_flag;
    LRUCache *LC;
    ThreadPool *ThrPl;
    ConsistentHash *key_addr;
    std::vector<std::string> *ipport_list;
};
struct task_connect_oth{
    std::string addr;
    std::unordered_map<std::string, std::vector<std::string>> *ipport_and_key;
    LRUCache *LC;
};
//////////////////////////////
pthread_mutex_t transfertooth = PTHREAD_MUTEX_INITIALIZER;
pthread_rwlock_t ipchange_lock = PTHREAD_RWLOCK_INITIALIZER;
pthread_mutex_t task_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t tasklisten_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_rwlock_t rw_lock = PTHREAD_RWLOCK_INITIALIZER;

//////////////////////////




#endif /* CACHE_SERVER_HPP */
